package com.hexb.smh.config.shiro;

import com.hexb.smh.utils.MD5PasswordHelper;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import org.springframework.stereotype.Component;

/**
 * @author : hexb
 */
@Component
public class Md5CredentialsMatcher extends SimpleCredentialsMatcher {

    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        UsernamePasswordToken upToken = (UsernamePasswordToken) token;
        return equals(MD5PasswordHelper.getInstance().encryptPassword(
                new String(upToken.getPassword())),
                getCredentials(info));
    }
}
